<?PHP


/****************************************/
/************* IdeaLAN LLC **************/
/* Here is a file where profile page is */
/* executed from change ur name phone # */
/* check your logs etc.                 */
/****************************************/
/* SCRIPT: profile.php       VER: 0.1b  */
/* AUTHOR: Lukasz Piekarski             */
/* E-mail: lukasz@idealan.net           */
/****************************************/
if (empty($_SESSION["sesid"])) { header ("Location: ../in.php?e=0"); }
?>

    <div id="content">
        <div id="left">
            <div class="naglowek"><div class="pkt"></div>My Profile</div>
            <ul id="me">
                <li <? if ($view == "") { echo "id=\"press\""; } ?> ><a href="in.php?show=profile">Change Personal Info</a></li>
                <li <? if ($view == "password") { echo "id=\"press\" "; } ?> ><a href="in.php?show=profile&view=password">Change Password</a></li>
                <li <? if ($view == "logs") { echo "id=\"press\" "; } ?> ><a href="in.php?show=profile&view=logs">My Logs</a></li>
            </ul>
        </div>					

        <div id="right">
<?
if (!$view) {

if (!empty($info_user_lastlogin)) { 
$info_user_lastlogin_date = date("d.m.Y - h:iA", $info_user_lastlogin); 
$info_user_logindns = gethostbyaddr($info_user_logindns);

$time_from_last_login_s = $timedate - $info_user_lastlogin;
$time_from_last_login_m = floor($time_from_last_login_s / 60);
$time_from_last_login_h = floor($time_from_last_login_m / 60);
$time_from_last_login_d = floor($time_from_last_login_h / 24);

if ($time_from_last_login_s <= 60) { $how_long_ago = "$time_from_last_login_s seconds ago."; } 
else if ($time_from_last_login_s <= 3600) { $how_long_ago = "$time_from_last_login_m minutes ago."; } 
else if ($time_from_last_login_s <= 3600) { $how_long_ago = "$time_from_last_login_h hours ago."; }
else if ($time_from_last_login_s >= 86400) { $how_long_ago = "$time_from_last_login_d Day(s) ago."; }

}

if ($info_user_set_timeout == "600") { $o1 = "SELECTED"; }
if ($info_user_set_timeout == "1200") { $o2 = "SELECTED"; }
if ($info_user_set_timeout == "2400") { $o3 = "SELECTED"; }
if ($info_user_set_timeout == "3600") { $o4 = "SELECTED"; }

?>
<div class='naglowek'><div class='pkt'></div>General Informations</div>
<div id='rightcont'>
<form method='POST' action='modify.php?act=save'>
<input type='hidden' name='what' value='profile'>
<input type='hidden' name='cat' value='info'>
<table style='width: 100%' class='editform1'>
	<tr>
		<td style='width: 145px' class='table1'>User ID:</td>
		<td class='table3'>&nbsp;<?php echo $info_user_id ?></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Username:</td>
		<td class='table3'>&nbsp;<?php echo $info_user_name ?></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Added:</td>
		<td class='table2'>&nbsp;<?php echo $info_user_adddate ?></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>First Name:</td>
		<td class='table2'><input name="finfo_user_fname" type="text" class="input_form" id="finfo_user_fname" value="<?php echo $info_user_fname ?>"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Last: Name:</td>
		<td class='table2'><input name="finfo_user_lname" type="text" class="input_form" id="finfo_user_lname" value="<?php echo $info_user_lname ?>"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Phone:</td>
		<td class='table2'><input name="finfo_user_phone" type="text" class="input_form" id="finfo_user_phone" value="<?php echo $info_user_phone ?>"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>E-mail:</td>
		<td class='table2'><input name="finfo_user_email" type="text" class="input_form" id="finfo_user_email" value="<?php echo $info_user_email ?>"></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Time OUT:</td>
		<td class='table2'><select name="finfo_user_set_timeout" class="input_form"><option value="600" <?php echo $o1 ?>>10 Minutes</option><option value="1200" <?php echo $o2 ?>>20 Minutes</option><option value="2400" <?php echo $o3 ?>>40 Minutes</option><option value="3600" <?php echo $o4 ?>>60 Minutes</option></select></td>


	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>User Level</td>
		<td class='table2'>&nbsp;<?php echo $info_user_rank ?></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Last Logged In:</td>
		<td class='table2'>&nbsp;<?php echo $info_user_lastlogin_date ?> (<i>$how_long_ago</i>)</td>
	</tr>
	<tr>
		<td style='width: 160px' class='table1'>Last Logged In From:</td>
		<td class='table2'>&nbsp;<?php echo $info_user_logindns ?></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Last Login failed:</td>
		<td class='table2'>&nbsp;<?php echo $info_user_loginfail ?></td>
	</tr>

</table>
<p>&nbsp;</p>
<p>

    <input type="submit" class="button1" value="SAVE">
</form>
</p>
</div>
                    
<?php

}

if ($view == "password") {
?>
<div class='naglowek'><div class='pkt'></div>Change Password</div>
<div id='rightcont'>
<form method='POST' action='modify.php?act=save'>
<input type='hidden' name='what' value='profile'>
<input type='hidden' name='cat' value='password'>
<table class='editform1' style='width: 100%'>
	<tr>
		<td style='width: 145px' class='table1'>User ID:</td>
		<td class='table3'>&nbsp;<?php echo $info_user_id ?></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>Username:</td>
		<td class='table2'>&nbsp;<?php echo $info_user_name ?></td>
	</tr>
	<tr>
	  <td style='width: 145px' class='table1'>OLD PASSWORD:</td>
	  <td class='table2'><input name='finfo_user_opass' type='password' class='input_form' id='finfo_user_opass' value=''></td>
	  </tr>
	<tr>
		<td style='width: 145px' class='table1'>NEW PASSWORD:</td>
		<td class='table2'><input name='finfo_user_npass' type='password' class='input_form' id='finfo_user_npass' value=''> (New password must contain at lest $passwordLengthMIN characters, but no more than $passwordLengthMAX)</td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>AGAIN NEW PASSWORD:</td>
		<td class='table2'><input name='finfo_user_anpass' type='password' class='input_form' id='finfo_user_anpass' value=''></td>
	</tr>
	<tr>
		<td style='width: 145px' class='table1'>&nbsp;</td>
		<td class='table2'>&nbsp;</td>
	</tr>

</table>
<p>&nbsp;</p>
<p>
  <input type='submit' class='button1' value='SAVE'>
</p>

</div>
<?php

}


if(isSet($_GET["begin"])) {
    $begin = $_GET["begin"];
} else {
    $begin = 0;
}

if ($view == "logs") {

    $rows_on_page = 10;
    $result = LogService::getInstance()->getUserNumRows($DBprefix,'LOGIN',$info_user_id,'log_id');
    $linktest ="in.php?show=profile&view=logs";
    include ("pages2.php");

    // LETS GET LOGS OF CURRENT USER
    $execute_get_user_logs = LogService::getInstance()->getLogLimitByUserIdAndAction($DBprefix,'LOGIN',$info_user_id,'log_id',$begin,25);
    $count_users_online = LogService::getInstance()->getUserActiveCount($DBprefix,'ACTIVE','LOGIN');

?>
    <div class='naglowek'><div class='pkt'></div>View Your Logs</div>
            <div id='rightcont'>
            <center><?php echo $pagingStr; ?></center>
                    <table class='editform1' style='width: 100%'>
                        <tr>
                            <td width='145' class='tableLogsHeader' style='width: 145px'>ID / ACTION</td>
                            <td width='145' class='tableLogsHeader'>DATE</td>
                            <td width='218' class='tableLogsHeader'>IP ADDRESS</td>
                            <td width='156' class='tableLogsHeader'>STATUS</td>
                            <td width='156' class='tableLogsHeader'>ENTRIES</td>
                            <td width='156' class='tableLogsHeader'>OPTIONS</td>
                        </tr>
<?php

foreach($execute_get_user_logs as $userLog) {
    $user_log_id = $userLog->getId();
    $user_log_action = $userLog->getAction();
    $user_log_userid = $userLog->getUserId();
    $user_log_pageto = $userLog->getPageTo();
    $user_log_pagefrom = $userLog->getPageFrom();
    $user_log_ip = $userLog->getIp();
    $user_log_date = $userLog->getDate();
    $user_log_indate = $userLog->getInDate();
    $user_log_outdate = $userLog->getOutDate();
    $user_log_status = $userLog->getStatus();
    $user_log_sesexp = $userLog->getSesExp();
    $user_log_sesid = $userLog->getSesId();
    
    $user_log_entries = SignupService::getInstance()->getUserCountByIdAndSessionId($DBprefix, $info_user_id, $user_log_sesid);

    if ($user_log_status == "ACTIVE") {
    ?>


             <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
                <td width='145' class='tableLogs' style='width: 145px'><?php echo "$user_log_id / $user_log_action" ?></td>
                <td width='145' class='tableLogs'><?php echo $user_log_date ?></td>
                <td width='218' class='tableLogs'><?php echo $user_log_ip ?></td>
                <td width='156' class='tableLogsgreen'><?php echo $user_log_status ?></td>
                <td width='156' class='tableLogs'><?php echo $user_log_entries ?></td>            
                <td width='156' class='tableLogs'><!-- OPTIONS --><a href='in.php?show=profile&view=detail&logid=$user_log_sesid'>MORE INFO</a></td>
             </tr>
    <?php
    } else {
    ?>


             <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
                <td width='145' class='tableLogs' style='width: 145px'><?php echo "$user_log_id / $user_log_action" ?></td>
                <td width='145' class='tableLogs'><?php echo $user_log_date ?></td>
                <td width='218' class='tableLogs'><?php echo $user_log_ip ?></td>
                <td width='156' class='tableLogs'><?php echo $user_log_status ?></td>
                <td width='156' class='tableLogs'><?php echo $user_log_entries ?></td>            
                <td width='156' class='tableLogs'><!-- OPTIONS --><a href='in.php?show=profile&view=detail&logid=$user_log_sesid'>MORE INFO</a></td>
             </tr>
    <?php
    }

}

    echo "</table>";
    echo $pagingStr;
    echo "</div>";
}

if ($view == "detail") {

// LETS GET LOGS OF CURRENT USER
$execute_get_user_logs = LogService::getInstance()->getLogBySessionId($DBprefix,$logid);
$user_log_adtries = LogService::getInstance()->getLogCountBySessionId($DBprefix,$logid);

if (empty($user_log_adtries)) { 
    header ("Location: in.php?e=1&NO_ENTRY"); 
}




echo "
        <div class='naglowek'><div class='pkt'></div>Detail log view of SESSION: $logid</div>
            <div id='rightcont'>
                <table class='editform1' style='width: 100%'>
                    <tr>
                        <td width='45' class='tableLogsHeader' style='width: 145px'>ID</td>
                        <td width='145' class='tableLogsHeader'>DATE</td>
                        <td width='145' class='tableLogsHeader'>ACTION</td>
                        <td width='156' class='tableLogsHeader'>PAGE FROM</td>
                        <td width='156' class='tableLogsHeader'>PAGE TO</td>
                    </tr>
";

foreach($execute_get_user_logs as $userLog) {
    
    $user_log_id = $userLog->getId();
    $user_log_action = $userLog->getAction();
    $user_log_userid = $userLog->getUserId();
    $user_log_pageto = $userLog->getPageTo();
    $user_log_pagefrom = $userLog->getPageFrom();
    $user_log_ip = $userLog->getIp();
    $user_log_date = $userLog->getDate();
    $user_log_indate = $userLog->getInDate();
    $user_log_outdate = $userLog->getOutDate();
    $user_log_status = $userLog->getStatus();
    $user_log_sesexp = $userLog->getSesExp();
    $user_log_sesid = $userLog->getSesId();

    ?>
     <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
        <td class='tableLogs' style='width: 145px'><?php echo $user_log_id ?></td>
        <td class='tableLogs'><?php echo $user_log_date ?></td>
        <td class='tableLogs'><?php echo $user_log_action ?></td>
        <td class='tableLogs'><?php echo $user_log_pagefrom ?></td>
        <td class='tableLogs'><?php echo $user_log_pageto ?></td>
     </tr>
    <?php
} 



echo "
</table>
</div>
";


}



?>
    </div>
</div>